/********************************************************************************
* Description: 
* Author: hsqiang
* Create Date: 2023-06-22
********************************************************************************/
#ifndef EVENT_CALLBACK_HPP_
#define EVENT_CALLBACK_HPP_

#include "noncopyable.hpp"
#include "socket.hpp"
#include <memory>
#include <functional>

namespace event_framework
{
    /**************** use oop as callback ****************/
    // the callback which all reactive fd myable interested in
    using ReadableCallback = std::function<void(const Socket&)>;
    using WriteableCallback = std::function<void(const Socket&)>;
    using ClosedCallback = std::function<void(const Socket&)>;
    using ExceptionCallback = std::function<void(const Socket&, int)>;
    // the four basic event
    struct EventCallback
    {
        EventCallback() = default;
        ~EventCallback() = default;
        EventCallback(EventCallback&& cb)
        {
            if (&cb == this)
            {
                return;
            }
            readableCallback = cb.readableCallback;
            writeableCallback = cb.writeableCallback;
            closedCallback = cb.closedCallback;
            exceptionCallback = cb.exceptionCallback;
        }
        EventCallback& operator=(EventCallback&& cb)
        {
            if (&cb != this)
            {
                readableCallback = cb.readableCallback;
                writeableCallback = cb.writeableCallback;
                closedCallback = cb.closedCallback;
                exceptionCallback = cb.exceptionCallback;
            }
            return *this;
        }
        ReadableCallback readableCallback;
        WriteableCallback writeableCallback;
        ClosedCallback closedCallback;
        ExceptionCallback exceptionCallback;
    };
    using EventCallbackPtr = std::unique_ptr<EventCallback>;

}

#endif